﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class TheloaiDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public TheloaiDataAccess()
        {
            _provider.connect();
        }
        public void inserttheloai(TheloaiInfo info)
        {
            DataTable dt = new DataTable();
            dt = LayDSTheloai();
            int i = dt.Rows.Count+1;
            string insertCommand = "insert into dbo.THELOAISACH(MATHELOAI, TENTHELOAI) values('TL" + i + "'," + "N'" + info.Tentheloai + "')";

            _provider.executeNonQuery(insertCommand);
        }
        public void updatetheloai(TheloaiInfo info)
        {

            string updateCommnad = "Update dbo.THELOAISACH Set TENTHELOAI= N'"
                            + info.Tentheloai
                            + "' Where MATHELOAI = '" + info.Matheloai + "'";
            _provider.executeNonQuery(updateCommnad);
            
            
        }
        public void updatetheloaidausach(DausachInfo info)
        {
            string updateCommand = "Update dbo.DAUSACH set MATHELOAI = " + info.Matheloai + "'Where MATHELOAI = '" + info.Matheloai + "'";
            _provider.executeNonQuery(updateCommand);
        }
        
        public void deletetheloai(TheloaiInfo info)
        {
            string deleteCommand = "DELETE FROM dbo.THELOAISACH WHERE MATHELOAI = '" + info.Matheloai + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public DataTable LayDSTheloai()
        {
            return _provider.GetData("select * from dbo.THELOAISACH order by MATHELOAI desc");
        }
        public DataTable timtl()
        {
            return _provider.GetData("select * from dbo.THELOAISACH WHERE TENTHELOAI LIKE '" + frmTheLoaiSach.timtl + "%'");
        }
    }
}
